<%@ page language="java"
	import="myclass.*,java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>购物车</title>
</head>
<body>
	<%
		String id = request.getParameter("id");
		String count = request.getParameter("count");
		ShopCar shopCar = (ShopCar) session.getAttribute("shopCar");
		Db db=new Db();
		if (id != null && id.length() > 0 && count != null && count.length() > 0) {
			Goods goods=db.getGoodsList().get(id);
			goods.setId(id);
			goods.setCount(Integer.valueOf(count));
			if (shopCar == null) {
				shopCar=new ShopCar();
				shopCar.getGoodsList().add(goods);
			}else{
				if (shopCar.getGoodsList().contains(goods)){
					Goods inCarGoods=shopCar.getGoodsList().get(shopCar.getGoodsList().indexOf(goods));
					inCarGoods.setCount(inCarGoods.getCount()+goods.getCount());
				}else{
					shopCar.getGoodsList().add(goods);
				}
			}
			session.setAttribute("shopCar", shopCar);
		}
		if (shopCar != null) {
	%>
	<table>
		<tr>
			<td>订单编号</td>
			<td>商品编号</td>
			<td>商品名称</td>
			<td>购买数量</td>
			<td>商品价格</td>
			<td>备注</td>
		</tr>
		<%
			for (Goods goods : shopCar.getGoodsList()) {
		%>
		<tr>
			<td><%=new Date()%></td>
			<td><%=goods.getId()%></td>
			<td><%=goods.getName()%></td>
			<td><%=goods.getCount()%></td>
			<td><%=goods.getPrice()%>
			<td></td>
		</tr>

		<%
			}
		%>
	</table>

	<%
		}
	%>

</body>
</html>